package com.chenyongjing.design.pattern.interpreter.calculate;

/**
 * @Author chen
 * @Date 2022/11/27 18:28
 */
public class OperatorUtil {
    /**
     * 判断是否为操作符
     * @param symbol
     * @return
     */
    public static boolean ifOperator(String symbol){
        return (symbol.equals("+")||symbol.equals("-")||symbol.equals("*")||symbol.equals("/"));
    }

    public static Interpreter getInterpreter(IArithmeticInterpreter left,IArithmeticInterpreter right,String symbol){
        if (symbol.equals("+")){
            return new AddInterpreter(left,right);
        }else if (symbol.equals("-")){
            return new SubInterpreter(left,right);
        }else if (symbol.equals("*")){
            return new MultilInterpreter(left,right);
        }else if (symbol.equals("/")){
            return new DivInterpreter(left,right);
        }
        return null;
    }
}
